<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('我发起的流程')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <div class="row">
                        <ul>
                             <li>
                                <label>流程名称：</label>
                                <input type="text" name="processDefinitionName"/>
                             </li>
                             <li>
                                <label>单号：</label>
                                <input type="text" name="businessKey"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>

                        </ul>
                    </div>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
        </div>

    </div>
</div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: select2-js" />
     <script th:inline="javascript">
         var prefixFlow = ctx + "flow";
         var todoList = [[${@permission.hasPermi('flow:get:todoList')}]];
         var transferTask = [[${@permission.hasPermi('flow:process:transferTask')}]];
         var delegateTask = [[${@permission.hasPermi('flow:process:delegateTask')}]];
         var processType = [[${@dict.getType('sys_process_type')}]];
         $(function() {
             var options = {
                 id: "bootstrap-table",
                 formId:"formId",
                 url: prefixFlow + "/findTasksByUserId",
                 striped: true,
                 showToggle: false,
                 loadingFontSize:20,
                 showRefresh: false,                   // 是否显示刷新按钮
                 showColumns: false,                   // 是否显示隐藏某列下拉框
                 showToggle: false,
                 showSearch: false,                     // 是否显示检索信息
                 modalName: "我的待办",
                 columns: [{
                     title: '序号',
                     formatter: function (value, row, index) {
                         return index+1;
                     }
                 },
                     {
                         field: 'taskId',
                         title: 'taskId',
                         visible: false
                     },
                     {
                         field: 'processType',
                         title: '流程类型',
                         formatter: function(value, row, index) {
                             return $.table.selectDictLabel(processType, value);
                         }
                     },
                     {
                         field: 'processDefinitionName',
                         title: '流程名称'
                     },
                     {
                         field: 'businessKey',
                         title: '单号'

                     },

                     {
                         field: 'taskName',
                         title: '审批节点'

                     },
                     {
                         field: 'startUserName',
                         title: '流程发起人'
                     },
                     {
                         field: 'startTime',
                         title: '流程发起时间'
                     },
                     {
                         field: 'createDate',
                         title: '任务创建时间'
                     },

                     {
                         title: '操作',
                         align: 'center',
                         formatter: function(value, row, index) {
                             var actions = [];
                             var processType=row.processType;
                             actions.push('<a class="btn btn-warning btn-xs ' + delegateTask + '" href="javascript:void(0)" onclick="selectDelegateTaskUser(\''+row.taskId+'\')"><i class="fa fa-wifi"></i>委派</a> ');
                             actions.push('<a class="btn btn-primary btn-xs ' + transferTask + '" href="javascript:void(0)" onclick="selectTransferTaskUser(\''+row.taskId+'\')"><i class="fa fa-tasks"></i>转办</a> ');
                             if(processType=='FORM_PROCESS'){
                                 actions.push('<a class="btn btn-success btn-xs ' + todoList + '" href="javascript:void(0)" onclick="cancelFormTask(\''+row.taskId+'\')"><i class="fa fa-edit"></i>处理</a> ');
                             }else {
                                 actions.push('<a class="btn btn-success btn-xs ' + todoList + '" href="javascript:void(0)" onclick="cancelApiTask(\''+row.taskId+'\')"><i class="fa fa-edit"></i>处理</a> ');
                             }

                             return actions.join('');
                         }
                     }]
             };
             $.table.init(options);
         });

         function cancelApiTask(taskId) {
             var preViewUrl=prefixFlow+'/toFinishTask?taskId='+taskId;
             $.modal.openTab("审批", preViewUrl);
         }

         function cancelFormTask(taskId) {
             var preViewUrl='toFinishTask?taskId='+taskId;
             $.modal.openTab("审批", preViewUrl);
         }

         function selectDelegateTaskUser(taskId) {
             var url = prefixFlow + '/selectUser?taskId='+taskId+'&flag=0';
             $.modal.open("选择委派用户", url);
         }

         function selectTransferTaskUser(taskId) {
             var url = prefixFlow + '/selectUser?taskId='+taskId+'&flag=1';
             $.modal.open("选择转办用户", url);
         }

     </script>
</body>
</html>